package com.album.activity.page;


import com.album.R;
import com.album.activity.SetstateManager;
import com.album.activity.pageView.CasualLookView;
import com.album.activity.pageView.MyFriendsView;
import com.album.activity.pageView.MyPhotoView;
import com.album.activity.pageView.UserLoginView;
import com.album.utils.CommonUtil;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

public class MenuBar implements OnClickListener{
	
	private PageManager manager;
	private LinearLayout menuBar;
//	private ImageView ivMenuBuddy;
//	private ImageView ivMenuChat;
//	private ImageView ivMenuSave;
	private Button ivButtonLook;
	private Button ivButtonImage;
	private Button ivButtonfriends;
	private Context ctx;
	public MenuBar(PageManager manager,Context ctx){
		this.manager = manager;
		this.ctx = ctx;
		initLayout();
	}
	
	public View getView(){
		return menuBar;
	}
	
	private void initLayout(){
		menuBar = (LinearLayout)LayoutInflater.from(ctx).inflate(R.layout.menubar, null);
		ivButtonLook = (Button)menuBar.findViewById(R.id.iv_button_look);
		ivButtonImage = (Button)menuBar.findViewById(R.id.iv_button_myImage);
		ivButtonfriends = (Button)menuBar.findViewById(R.id.iv_button_myfirends);
		
		ivButtonLook.setOnClickListener(this);
		ivButtonImage.setOnClickListener(this);
		ivButtonfriends.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		try {
			if (v == ivButtonLook) {
				// 随便看看页面
				Log.i("", "ivButtonLook");
				ivButtonLook.setBackgroundResource(R.drawable.casuallook_2);
				ivButtonImage.setBackgroundResource(R.drawable.myphoto_1);
				ivButtonfriends.setBackgroundResource(R.drawable.myfriends_1);
				SetstateManager.setBacktoState(CasualLookView.class,manager);
				SetstateManager.setRefresState(CasualLookView.class,manager);
				manager.activePage(CasualLookView.class, null);
			} else if (v == ivButtonImage) {
				// 我的相册页面
				ivButtonLook.setBackgroundResource(R.drawable.casuallook_1);
				ivButtonImage.setBackgroundResource(R.drawable.myphoto_2);
				ivButtonfriends.setBackgroundResource(R.drawable.myfriends_1);
				if(CommonUtil.isUserLogin(manager.getContext())){
					SetstateManager.setBacktoState(MyPhotoView.class,manager);
					SetstateManager.setRefresState(MyPhotoView.class, manager);
				    manager.activePage(MyPhotoView.class, null);
				}else{
					SetstateManager.setRefresState(UserLoginView.class, manager);
					UserLoginView.setClass(MyPhotoView.class);
					manager.activePage(UserLoginView.class, null);
				}
				
			} else if (v == ivButtonfriends) {
				// 我的好友页面
				ivButtonLook.setBackgroundResource(R.drawable.casuallook_1);
				ivButtonImage.setBackgroundResource(R.drawable.myphoto_1);
				ivButtonfriends.setBackgroundResource(R.drawable.myfriends_2);
				if(CommonUtil.isUserLogin(manager.getContext())){
					SetstateManager.setBacktoState(MyFriendsView.class,manager);
					SetstateManager.setRefresState(MyFriendsView.class, manager);
					manager.activePage(MyFriendsView.class, null);
				}else{
					SetstateManager.setRefresState(UserLoginView.class, manager);
					UserLoginView.setClass(MyFriendsView.class);
					manager.activePage(UserLoginView.class, null);
				}
				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void setMenuVisible(boolean visible){
		if(visible)
			menuBar.setVisibility(View.VISIBLE);
		else
			menuBar.setVisibility(View.GONE);
	}

}
